package com.yznote.cloudesk.terminal;

import com.yznote.cloudesk.common.Anno.CollectLogs;
import com.yznote.cloudesk.common.constants.ModuleConstant;
import com.yznote.cloudesk.common.pojo.Result;
import com.yznote.cloudesk.common.pojo.TerminalUser;
import com.yznote.cloudesk.common.pojo.User;
import com.yznote.cloudesk.common.tokenShare.YTokenShare;
import com.yznote.cloudesk.compileservice.TerminalService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/terminal")
@Api(tags="终端控制器")
@CollectLogs(moduleName = ModuleConstant.TERMINAL_MODULE)
public class TerminalController {
    @Autowired
    TerminalService terminalService;
    @Autowired
    YTokenShare tokenShare;
    @ApiOperation("连接终端")
    @PostMapping("/connect")
    @CollectLogs(needParam = false,moduleName = ModuleConstant.TERMINAL_MODULE)
    public Result connect(@RequestBody TerminalUser terminalUser) {
        User user = tokenShare.get();
        return terminalService.connect(user.getUserId(), terminalUser.getName(), terminalUser.getPassword(), terminalUser.getHost(), terminalUser.getPort());
    }
    @ApiOperation("发送命令至终端")
    @GetMapping("/sendCmd")
    public Result sendCmd(@RequestParam("cmd") String cmd){
    User user = tokenShare.get();
    return terminalService.sendCmd(user.getUserId(),cmd);
    }
}
